package com.sanfu.etl.pojo;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Repository;

import java.util.Properties;
// *********************
// ** @Date: 2021-06-29
// ** @Author: Camemax
// ** @Description: Kafka配置实体类
// *********************
@Repository
@ConfigurationProperties(prefix = "flink.kafka")
public class KafkaProps {
    private final Consumer consumerA = new Consumer();
    private final Consumer consumerB = new Consumer();

    public Consumer getConsumerA() {
        return this.consumerA;
    }

    public Consumer getConsumerB(){
        return this.consumerB;
    }

    public static class Consumer {
        private String bootstrapServers;
        private String autoOffsetReset;
        private String groupId;
        private String topic;

        public String getBootStrapServers() {
            return bootstrapServers;
        }

        public void setBootStrapServers(String server) {
            this.bootstrapServers = server;
        }

        public String getAutoOffsetReset() {
            return autoOffsetReset;
        }

        public void setAutoOffsetReset(String autoOffsetReset) {
            this.autoOffsetReset = autoOffsetReset;
        }

        public String getGroupId() {
            return groupId;
        }

        public void setGroupId(String groupId) {
            this.groupId = groupId;
        }

        public String getTopic() {
            return topic;
        }

        public void setTopic(String topic) {
            this.topic = topic;
        }

        public Properties kafkaProps(){
            Properties props = new Properties();
            props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
            props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
            props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
            props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
            props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
            return props;
        }
    }
}
